/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef SIM_FRAME2_H
#define SIM_FRAME2_H

#include <wx/wx.h>
#include <wx/glcanvas.h>
#include <wx/menu.h>
#include "ownutils.h"

#include "GLCanvas.h"
#include "GLProvider.h"

#define MENUITEM_OPEN 1000
#define MENUITEM_EXIT 1001
#define MENUITEM_PAUSE 1002
//#define MENUITEM_MODE 1003
#define MENUITEM_REALT 1004
#define MENUITEM_ABOUT 1005

class CWorld;

#ifdef USE_OWNTHREADS
class SimFrame2 : public wxFrame, public CGLProvider
#else
class SimFrame2 : public wxFrame, public CGLProvider, private wxThread
#endif
{
  DECLARE_EVENT_TABLE()
	public:
		SimFrame2( wxWindow* parent, int id = wxID_ANY, wxString title = _T("FSRSim"),
              wxPoint pos = wxDefaultPosition, wxSize size = wxSize( 577,470 ),
              int style = wxDEFAULT_FRAME_STYLE/*|wxTAB_TRAVERSAL*/ );

	  ~SimFrame2();

		//event handlers
		void OnOpen( wxCommandEvent& event );
		void OnExit( wxCommandEvent& event );
		void OnPause( wxCommandEvent& event );
		void OnRealTime( wxCommandEvent& event );
		void OnAbout( wxCommandEvent& event );
		void OnContextMenu(wxContextMenuEvent& event);
		void OnClose(wxCloseEvent& event);
		void OnKey(wxKeyEvent &e);
    void OnSize(wxSizeEvent &e);

    void OnPaint(wxPaintEvent &e);

    //
    void OpenFile(const char* file, int mode);

    //set opengl view right
    //void SetView();
    void ResetView();

    //GLProvider functions
    //void SetParams();
    void SetView();
    void SetContext();

    //these are forwarded to the simulation world
    //gimi settings to use...
    void SetGimiSettingsFile(std::string file);
    //...or optionally hub params
    void SetHub(std::string hub, int port);

    //thread entry point
#ifdef USE_OWNTHREADS
    static void* Entry(void*);
#else
    void* Entry();
#endif

	protected:
#ifdef USE_OWNTHREADS
    bool go;
    ownThreadHandle thread;
    ownMutexHandle pauseMutex;
    ownMutexHandle worldMutex;
    ownMutexHandle speedStringMutex;
#else
    wxMutex worldMutex;
    wxMutex speedStringMutex;
#endif

		wxStatusBar* StatusBar;
		wxMenuBar* Menubar;
		wxMenu* Menu_File;
		wxMenu* Menu_Simulation;
		wxMenu* Menu_Help;

		wxString speedString;


		bool running; //is simulation running
		bool realtime; //realtime mode
		int stepCount;
    int attribList[]; //opengl params for canvas
    CGLCanvas *GLCanvas;
    wxGLContext *GLContext;

    bool reset;//true if view resetting needed
    float z,y,x, pan,tilt;//camera params
    bool resized;

    CWorld *World;

    
    bool useGimiSettingsFile;
    std::string gimiSettingsFile;
    std::string hubAddress;
    int hubPort;

    //void initGL(); //init opengl
    void draw(); //render simulation graphics
};

#endif
